package com.yanqu.road.server.manger.union.listener;

import com.yanqu.road.entity.enums.eUnionPosition;
import com.yanqu.road.entity.enums.eUnionSyncType;
import com.yanqu.road.entity.union.cross.CrossUnionInfo;
import com.yanqu.road.entity.union.cross.CrossUnionMember;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.manger.ICrossUnionSyncListener;
import com.yanqu.road.server.manger.activity.rankunionwar.RankUnionWarMgr;

import java.util.ArrayList;
import java.util.List;

/**
 * 癫疯商会战活动监听
 */
public class RankUnionWarListener implements ICrossUnionSyncListener {

    @Override
    public void notifySync(int syncType, long playerId, CrossUnionInfo unionInfo, List<CrossUnionMember> memberList) {


        List<Long> userIdList = new ArrayList<>();
        for (CrossUnionMember member : memberList) {
            if(member.getServerId() == GameServer.getInstance().getServerId()){
                userIdList.add(member.getUserId());
            }
        }
        if(userIdList.size() > 0){
            if(syncType == eUnionSyncType.BeKick.getValue() || syncType == eUnionSyncType.QuitUnion.getValue()){
                RankUnionWarMgr.quitUnionSendCross(unionInfo.getUnionUid(),userIdList);
            }

            if(syncType == eUnionSyncType.JoinUnion.getValue()){
                List<CrossUnionMember> needMemberList = new ArrayList<>();
                for(CrossUnionMember member : memberList){
                    if(userIdList.contains(member.getUserId())){
                        needMemberList.add(member);
                    }
                }
                RankUnionWarMgr.joinUnionSendCross(unionInfo.getUnionUid(),needMemberList);
            }

            if(syncType == eUnionSyncType.SetPosition.getValue()){
                List<CrossUnionMember> needMemberList = new ArrayList<>();
                for(CrossUnionMember member : memberList){
                    if(userIdList.contains(member.getUserId())){
                        needMemberList.add(member);
                    }
                }
                RankUnionWarMgr.positionUnionSendCross(needMemberList);
            }
        }
    }
}
